<?php
class Zend_View_Helper_PageTree
{
	public $view;
	public $t;

	public function setView(Zend_View_Interface $view)
	{
		$this->view = $view;
		$this->t = Zend_Registry::get('Zend_Translate');
	}

	public function pageTree($pages = array(), $type = '')
	{
		$tree = '<ul>';
		foreach($pages as $pageId => $page) {
			$pageName = '';
			if(array_key_exists('name', $page)) {
				if(is_array($page['name'])) {
					foreach($page['name'] as $pageL10N) {
						if(empty($pageName)) {
							$pageName .= $pageL10N;
						} else {
							$pageName .= " ({$pageL10N})";
						}
					}
				}
			}

			switch($type) {
				case 'admin':
					$link = 'admin/page/save/';
				break;

				default:
					$link = 'page/view/';
				break;
			}
			$tree .= "<li><a href=\"{$this->view->baseUrl()}/{$link}id/{$pageId}\">{$pageName}</a>";

			if(array_key_exists('children', $page)) {
				$tree .= $this->pageTree($page['children'], $type);
			}

			$tree .= "</li>";
		}
		$tree .= '</ul>';

		return $tree;
	}
}